package com.scsystem.xysc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scsystem.xysc.mapper.AddressMapper;
import com.scsystem.xysc.pojo.Address;
import com.scsystem.xysc.pojo.vo.ReturnResult;
import com.scsystem.xysc.service.AddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhoub
 */
@RestController
@Transactional
@CrossOrigin
@Tag(name = "地址接口")
@RequestMapping("/address")
public class AddressController {

    @Resource
    AddressMapper addressMapper;

    @PostMapping("insertAddress")
    @Operation(summary = "添加地址")
    public ReturnResult<Boolean> insertAddress(Integer userId,String addressName) {
        Address address = new Address();
        address.setUserId(userId);
        address.setAddressName(addressName);
        int insert = addressMapper.insert(address);
        if (insert != 0) {
            return new ReturnResult<>(200, "添加成功");
        }
        return new ReturnResult<>(500, "添加失败");
    }

    @PostMapping("updateAddress")
    @Operation(summary = "修改地址")
    public ReturnResult<Boolean> updateAddress(Integer addressId,String addressName) {
        Address address = new Address();
        address.setAddressId(addressId);
        address.setAddressName(addressName);
        int updateById = addressMapper.updateById(address);
        if (updateById != 0) {
            return new ReturnResult<>(200, "修改成功");
        }
        return new ReturnResult<>(500, "修改失败");
    }

    @PostMapping("deleteAddress")
    @Operation(summary = "删除地址")
    public ReturnResult<Boolean> deleteAddress(Integer addressId) {
        int deleteById = addressMapper.deleteById(addressId);
        if (deleteById != 0) {
            return new ReturnResult<>(200, "删除成功");
        }
        return new ReturnResult<>(500, "删除失败");
    }
}
